import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:xlsk/view/class/classInfo.dart';
import 'package:xlsk/view/class/classList.dart';
import 'package:xlsk/view/class/classRecord.dart';
import 'package:xlsk/view/hudong/index.dart';
import 'package:xlsk/view/index.dart';
import 'package:xlsk/view/count.dart';
import 'package:xlsk/view/login/code.dart';
import 'package:xlsk/view/login/index.dart';
import 'package:xlsk/view/my/index.dart';
import 'package:xlsk/view/notice/qingjia.dart';
import 'package:xlsk/view/student/info.dart';
import 'package:xlsk/view/student/list.dart';

class XlskRouter {
  static final router = FluroRouter();

  static final routes = {
    '/':Handler(
      handlerFunc: (ctx,params) => Index()
    ),
    '/count':Handler(
      handlerFunc: (ctx,params) => Count()
    ),
    '/hudong':Handler(
      handlerFunc: (ctx,params) => Hudong()
    ),
    '/my':Handler(
      handlerFunc: (ctx,params) => My()
    ),

    '/login':Handler(
      handlerFunc: (ctx,params) => Login()
    ),
    '/login/code':Handler(
      handlerFunc: (context,params){
        var phone = params['phone']?.first;
        return Code(phone: phone);
      }
    ),

    '/qinjia':Handler(
      handlerFunc: (ctx,params) => Qingjia()
    ),
    '/student/list':Handler(
      handlerFunc: (ctx,params) => StudentList()
    ),
    '/student/info':Handler(
      handlerFunc: (ctx,params){
        var id = params['id']?.first;
        return StudentInfo(id: id);
      }
    ),

    '/class/list':Handler(
      handlerFunc: (ctx,params) => ClassList()
    ),
    '/class/info':Handler(
      handlerFunc: (ctx,params){
        var id = params['id']?.first;
        return ClassInfo(id: id);
      }
    ),
    '/classRecord':Handler(
      handlerFunc: (ctx,params) => ClassRecord()
    )
  };

  static void init(){
    routes.forEach((key, value) {
      router.define(key,handler: value);
    });
  }

  static void go(BuildContext context,path,[arguments]){
    router.navigateTo(context, path ,routeSettings: RouteSettings(
      arguments:arguments,
    ),transition: TransitionType.cupertino);
  }

  static void goRemoveUntil(BuildContext context,path){
    Navigator.of(context).pushNamedAndRemoveUntil(path, (Route<dynamic> route) => false);
  }

  static void back(BuildContext context){
    router.pop(context);
  }
}
